const path = require('node:path')
const nodeExternals = require('webpack-node-externals')
const CopyPlugin = require('copy-webpack-plugin')

const isDev = process.env.NODE_ENV === 'development'

module.exports = {
  target: 'node',
  mode: process.env.NODE_ENV || 'development',
  entry: './index.js',
  output: {
    filename: '[name].js',
    path: path.resolve(__dirname, 'dist'),
    clean: true,
  },
  resolve: {
    alias: {
      '@': path.resolve(__dirname, 'src'),
    },
  },
  plugins: [
    new CopyPlugin({
      patterns: [{ from: './deploy.sh', to: path.resolve(__dirname, './dist') }],
    }),
  ],
  stats: isDev ? 'errors-only' : 'normal',
  devtool: isDev ? 'inline-source-map' : 'source-map',
  externals: isDev ? [nodeExternals()] : [],
}
